﻿#include "Tracer.h"
#include "CommandPipe.h"
using namespace libemb;

void TestCommandPipe()
{
    while (1) 
    {
        TRACE_YELLOW("-------CommandPipe test------.\n");
        TRACE_YELLOW("1 ---> execute test.\n");
        TRACE_YELLOW("2 ---> execute timeout test.\n");
        TRACE_YELLOW("quit/q ---> quit test.\n");
        
        std::string inputStr;
        std::cin >> inputStr;
        std::cout << inputStr << std::endl;
        if ("q" == inputStr || "quit" == inputStr)
        {
            break;
        }
        else if("1"==inputStr)
        {
            std::string cmd = "route del default 2>&1"; 
            std::string result = CommandPipe::execute(cmd);
            printf("\nCommandPipe::execute(cmd) return:[%s]\n",result.c_str());
            int ret = CommandPipe::execute(cmd,result);
            printf("\nCommandPipe::execute(cmd,result),return:[%d],result:[%s]\n",ret,result.c_str());
            continue;
        }
        else if("2"==inputStr)
        {
            std::string cmd = "ping 192.168.125.120"; 
            std::string result;
            printf("------execute:%s\n",cmd.c_str());
            int ret = CommandPipe::execute(cmd,result,10);
            printf("\nCommandPipe::execute(cmd,result),return:[%d],result:[%s]\n",ret,result.c_str());
            continue;
        }
        
    }
}